//
//  MPTLivePushView.m
//  MPTLive
//
//  Created by HouGeng on 16/2/25.
//  Copyright © 2016年 Jeakin. All rights reserved.
//

#import "MPTLivePushView.h"

@implementation MPTLivePushView

- (id)initWithFrame:(CGRect)frame dic:(NSDictionary *)dict
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        self.userInteractionEnabled = YES;
        
        id alert = [[dict objectForKey:@"aps"] objectForKey:@"alert"];
        
        TPLabel *lab = [TPLabel getWithFrame:CGRectMake(15, 0, screenW - 42 - 45, 64)
                                        text:alert
                                   textColor:RGBAllColor(0xFFE200)
                                    textFont:[UIFont systemFontOfSize:15]];
        lab.numberOfLines = 0;
        [self addSubview:lab];
        self.image = [UIImage imageNamed:@"pushBeijing"];
        
        
        TPButton *but = [TPButton getWithFrame:CGRectMake(CGRectGetMaxX(lab.frame) + 15, (64 - 42) / 2, 42, 42) target:self action:@selector(butClicked)];
        [but setImage:[UIImage imageNamed:@"pushbofang"] forState:UIControlStateNormal];
        [self addSubview:but];
        
        [self performSelector:@selector(remove) withObject:self afterDelay:5];
    }
    
    return self;
}

- (void)butClicked
{
    if (self.block)
    {
        self.block();
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [self removeFromSuperview];
    }
}

- (void)remove
{
    [UIView animateWithDuration:0.3 animations:^{
        self.frame = CGRectMake(0, -64, screenW, 64);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
